package com.example.arithmeticleetcode.leetcode;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @program: arithmetic-leetcode
 * @description: 961. 重复 N 次的元素
 * @author: FangZhen
 * @create: 2020-05-21 19:40
 **/
public class Demo22 {

    public static void main(String[] args) {
        int[] arr1 = {1, 2, 3, 3};
        int[] arr2 = {2, 1, 2, 5, 3, 2};
        int[] arr3 = {5, 1, 5, 2, 5, 3, 5, 4};
        System.out.println(repeatedNTimes(arr1));
        System.out.println(repeatedNTimes(arr2));
        System.out.println(repeatedNTimes(arr3));
    }

    public static int repeatedNTimes(int[] A) {
        List<Integer> list = new ArrayList<>(A.length);
        int result = -1;
        for (int i : A) {
            if (!list.contains(i)) {
                list.add(i);
            } else {
                result = i;
                break;
            }
        }
        return result;
    }
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class A {
    private String username = "a";
}

@Data
@AllArgsConstructor
@NoArgsConstructor
class B {
    String nickname = "b";
}

